#include "FontRenderer.hpp"

#include "../Core.hpp"

FontRenderer::FontRenderer(Core*core)
{
    m_core = core;
    if(!m_font.loadFromFile("Ressources/Fonts/PixelFont.ttf"))
    {
        exit(0);
    }
}

FontRenderer::~FontRenderer()
{

}

void FontRenderer::printString(std::string str, int x, int y, sf::Color color, int charSize)
{
    sf::Text text;
    text.setFont(m_font);
    text.setString(str);
    text.setColor(color);
    text.setCharacterSize(charSize);
    text.setPosition(x,y);

    m_core->rWindow.draw(text);
}

void FontRenderer::printCenteredString(std::string str, sf::IntRect rect, sf::Color color, int charSize)
{
    sf::Text text;
    text.setFont(m_font);
    text.setString(str);
    text.setColor(color);
    text.setCharacterSize(charSize);
    text.setPosition(rect.left + rect.width/2 - text.getLocalBounds().width/2, rect.top + rect.height/2 );
    m_core->rWindow.draw(text);
    /*x = x + rectWidth/2 - (text.size()*(m_charWidth+ m_letterSpacing))/2 + 2;
    //std::cout<<"x :"<<x<<"\n";
    y = y + rectHeight/2- m_charHeight/2;
    for(int i=0; i<text.size();i++)
    {
        char letter = text[i];
        if(letter != ' ')
        {
            printChar(letter, x, y, image);
            int u = (m_frame % m_columns) * m_charWidth;
            int v = m_line* m_charHeight;
            //std::cout <<"u,v-------frame : "<<u<<","<<v<<"------"<<frame<<"\n";
            image->copy(m_img, x, y, sf::IntRect(u,v,m_charWidth, m_charHeight), false);
        }
        else
        {
            x-= 10;
        }
        x += m_charWidth + m_letterSpacing;
    }*/
}
